﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;
using IPTV.DBUtility;
using IPTV.module;
using System.Data;

/// <summary>
/// Summary description for PlateDao
/// </summary>
namespace IPTV.dao
{
    public class TeacherDao
    {
        public TeacherDao()
        {
            
        }

        public TeacherDto findTeacherById(string teacherId)
        {

            string sql = " SELECT t.id  , t.UserID ,  t.SchoolID   , t.Subject , t.Grade , t.Idcard , "
            + " t.EduBg , t.EduExp , t.StrongSuit , t.FileUri , t.Num , t.UserName , t.Name , t.Level , t.Introducter , "
            + " t.PactStatus , t.Remark , t.studentcount , t.hits , t.commentlevel , t.commentnum , t.answercount , t.credit , t.picOne , "
            + " t.picTwo , t.TeaChannel , t.ModifyIntro , t.Audit , t.publishstate , t.TeacherArtpic , t.teacherMark , s.name "
            + " FROM teacher t , subject s "
            + " WHERE t.publishstate = 1  AND t.id = @teacherId AND s.id = t.subject ";
           
            MySqlParameter[] parms = new MySqlParameter[] 
                { 
                    new MySqlParameter( "@teacherId" , MySqlDbType.VarChar, 36 )
                };

            parms[0].Value = teacherId;
            TeacherDto teacher = null;
            try
            {
                MySqlDataReader reader = MySQLHelper.ExecuteReader(MySQLHelper.CONNECTION_STRING, sql, parms);

                while (reader.Read())
                {
                    teacher = new TeacherDto();
                    teacher.Id = reader[0].ToString();
                    teacher.UserId = reader[1].ToString();
                    teacher.SchooleId = reader[2].ToString();
                    teacher.SubjectId = reader[3].ToString();
                    teacher.GradeId = reader[4].ToString();
                    teacher.IdCard = reader[5].ToString();
                    teacher.EduBg = reader[6].ToString();
                    teacher.EduExp = reader[7].ToString();
                    teacher.StrongSuit = reader[8].ToString();
                    teacher.FileUri = reader[9].ToString();
                    teacher.Num = reader[10].ToString();
                    teacher.UserName = reader[11].ToString();
                    teacher.Name = reader[12].ToString();
                    teacher.Level = reader[13].ToString();
                    teacher.Introducter = reader[14].ToString();
                    teacher.PactStatus = reader[15].ToString();
                    teacher.Remark = reader[16].ToString();
                    teacher.StudentCount = Convert.ToInt32(reader[17].ToString());
                    teacher.Hits = Convert.ToInt32(reader[18].ToString());
                    teacher.CommentLevel = Convert.ToInt32(reader[19].ToString());
                    teacher.CommentNum = Convert.ToInt32(reader[20].ToString());
                    teacher.AnswerCount = Convert.ToInt32(reader[21].ToString());
                    teacher.Credit = Convert.ToInt32(reader[22].ToString());
                    teacher.PicOne = reader[23].ToString();
                    teacher.PicTwo = reader[24].ToString();
                    teacher.TeaChannel = reader[25].ToString();
                    teacher.ModifyIntro = reader[26].ToString();
                    teacher.Audit = reader[27].ToString();
                    teacher.PublishState = Convert.ToInt32(reader[28].ToString());
                    teacher.TeacherArtpic = reader[29].ToString();
                    teacher.TeacherMark = Convert.ToInt32(reader[30].ToString());
                    teacher.SubjectName = reader[31].ToString();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("findTeacherById run error.");
            }

            return teacher;

        }
    }
}